The alternative to using withContext()
directly in the flow()
lambda
expression is to call flowOn()
on the Flow
, providing the dispatcher
that you want used for the lambda expression.
You can learn more about this in:
Tags:
A Conflated Channel
A Fixed-Buffer Channel
A Parallel Coroutine Sample
A Sequential Coroutine Sample
A Simple Channel
A Simple Coroutine Sample
A Simple Flow
A Simple SharedFlow
A Simple StateFlow
A Zero-Buffer Channel
async()
BroadcastChannel
cancelAndJoin()
Canceling a Job
Canceling a Parent Cancels Its Children
Canceling and Cooperation
catch()
Channel and receive()
Channels and Fan-out
combine() Operator
Contexts and Jobs
Cooperation by Checking isActive
Cooperation by Yielding
debounce() Operator
distinctUntilChanged() Operator
distinctUntilChangedBy() Operator
drop() Operator
dropWhile() Operator
filter() Operator
filterIsInstance() Operator
filterNot() Operator
filterNotNull() Operator
first() and Flow
flattenConcat() Operator
flattenMerge() Operator
Flow Actions
Flow onStart()
flowOf()
flowOn()
Flows and Exceptions
fold() Operator
Hot Channels Via offer()
invokeOnCompletion()
Jobs and Parents
Jobs Cancel When They Crash
join()
Lazy Coroutines
map() Operator
mapLatest() Operator
mapNotNull() Operator
Massively Parallel Coroutines
MutableSharedFlow Replay Option
Non-Cancellable Coroutines
Parent Jobs Cancel When a Child Crashes
promise()
retry()
retryWhen()
runBlocking()
sample() Operator
scan() Operator
single() and singleOrNull()
Starting Lazy Coroutines
StateFlow and Content Equality
suspend Functions and Flows
Suspending main()
take() Operator
takeWhile() Operator
The Channel() Function
TimeoutCancellationException
Timeouts
toList() and toSet()
toList() for Channel
withIndex() Operator
withTimeoutOrNull()
zip() Operator
A Simple Flow
A Simple SharedFlow
A Simple StateFlow
catch()
combine() Operator
debounce() Operator
distinctUntilChanged() Operator
distinctUntilChangedBy() Operator
drop() Operator
dropWhile() Operator
filter() Operator
filterIsInstance() Operator
filterNot() Operator
filterNotNull() Operator
first() and Flow
flattenConcat() Operator
flattenMerge() Operator
Flow Actions
Flow onStart()
flowOf()
flowOn()
Flows and Exceptions
fold() Operator
map() Operator
mapLatest() Operator
mapNotNull() Operator
MutableSharedFlow Replay Option
retry()
retryWhen()
sample() Operator
scan() Operator
single() and singleOrNull()
StateFlow and Content Equality
suspend Functions and Flows
take() Operator
takeWhile() Operator
toList() and toSet()
withIndex() Operator
zip() Operator